<?php

namespace app\admin\model\chase;

use think\Model;


class UserBalanceLog extends Model
{

    

    

    // 表名
    protected $table = 'user_balance_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'scene_text'
    ];
    

    
    public function getSceneList()
    {
        return ['1' => __('Scene 1'), '2' => __('Scene 2'), '3' => __('Scene 3'), '4' => __('Scene 4'), '5' => __('Scene 5')];
    }


    public function getSceneTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['scene']) ? $data['scene'] : '');
        $list = $this->getSceneList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }

    public static function add($order)
    {
        return self::create([
            'user_id' => $order->user_id,
            'money' => $order->total_amount,
            'scene' => 4,
            'description' => '订单退款：'.$order->order_no
        ]);
    }

}
